﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.BIM;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HYSpace
{
	public partial class FrmAddRoomName : System.Windows.Forms.Form
	{
		public FrmAddRoomName(int roomTypeId)
		{
			this.InitializeComponent();
			this.rTypeId = roomTypeId;
			base.Icon = Resource.YArchitechIcon;
		}

		private void FrmAddRoomName_Load(object sender, EventArgs e)
		{
			IList<RoomType> allRoomType = FrmShowInfoGrid.loadParam.GetAllRoomType();
			this.cmbRoomType.DataSource = allRoomType;
			this.cmbRoomType.DisplayMember = "RoomTypeName";
			this.cmbRoomType.ValueMember = "RoomTypeId";
			this.cmbRoomType.SelectedValue = this.rTypeId;
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			this.roomTID = Convert.ToInt32(this.cmbRoomType.SelectedValue);
			this.roomName = this.txtRoomName.Text.Trim();
			if (string.IsNullOrEmpty(this.roomName))
			{
				YJKMessageBox.Show("空间用途名不能为空，请重新填写！");
				this.txtRoomName.Focus();
				return;
			}
			bool flag = false;
			foreach (SpaceParameterInfo spaceParameterInfo in FrmShowInfoGrid.listSPI)
			{
				if (spaceParameterInfo.RoomTypeId == this.rTypeId && this.roomName == spaceParameterInfo.RoomName)
				{
					this.txtRoomName.Focus();
					this.txtRoomName.SelectAll();
					YJKMessageBox.Show("同类型空间，不能重名，请重新填写！");
					flag = true;
					break;
				}
			}
			if (flag)
			{
				return;
			}
			base.DialogResult = DialogResult.Yes;
		}

		private int rTypeId;

		public int roomTID;

		public string roomName = "";
	}
}
